import socket

# 创建 UDP socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 绑定地址和端口
server_address = ('localhost', 12345)
server_socket.bind(server_address)

print('等待客户端发送消息...')

while True:
    # 接收来自客户端的消息和地址信息
    data, client_address = server_socket.recvfrom(1024)
    print('收到来自 {} 的消息: {}'.format(client_address, data.decode()))

    # 发送回复消息给客户端
    reply_message = '收到你的消息了'
    server_socket.sendto(reply_message.encode(), client_address)
